package com.twq.patternmatch.pattern.kinds

/**
 * Created by tangweiqun on 2017/12/8.
 * 模式的种类-常量模式
 */
object Constant {
  def main(args: Array[String]): Unit = {

    //2、常量模式(Constant patterns)
    describe(5) //res6: String = five
    describe(true) //res7: String = truth
    describe("hello") //res8: String = hi!
    describe(Nil) //res9: String = the empty list
    describe(List(1, 2, 3)) //res10: String = something else

  }

  def describe(x: Any) = x match {
    case 5 => "five"
    case true => "truth"
    case "hello" => "hi!"
    case Nil => "the empty list"
    case _ => "something else"
  }
}
